<template>
	<view class="body">
		<view class="title-box" @click="back()">
			<!-- <view class="title">荷式拍卖列表</view> -->
			<text class="iconfont icon-left"></text>
		</view>
		<view class="item">
			<view class="title" style="display: flex;">
				原密码<span style="color: #D70000; display: block;">*</span>
			</view>
			<view class="in-ys">
				<input style="border: 0px;" placeholder="请输入原密码" type="safe-password" :password="showPassword" border="none" v-model="userInfo.password" />
				
				<uni-icons v-if="showPassword" type="eye-filled" size="15" @click="showPassword = false"></uni-icons>
				<uni-icons v-else type="eye-slash-filled" size="15"  @click="showPassword = true"></uni-icons>
			</view>
		</view>
		<view class="item">
			<view class="title" style="display: flex;">
				新密码<span style="color: #D70000; display: block;">*</span>
			</view>
			<view class="in-ys">
				<input style="border: 0px;" placeholder="请输入新密码" border="none" v-model="userInfo.newpassWord"  :password="showPassword1" />
				<uni-icons v-if="showPassword1" type="eye-filled" size="15" @click="showPassword1 = false"></uni-icons>
				<uni-icons v-else type="eye-slash-filled" size="15"  @click="showPassword1 = true"></uni-icons>
			</view>
		</view>
		<view class="item">
			<view class="title" style="display: flex;">
				确认密码<span style="color: #D70000; display: block;">*</span>
			</view>
			<view class="in-ys">
				<input style="border: 0px;" placeholder="请确认密码" border="none" v-model="userInfo.newpassWord1" :password="showPassword2"/>
				<uni-icons v-if="showPassword2" type="eye-filled" size="15" @click="showPassword2 = false"></uni-icons>
				<uni-icons v-else type="eye-slash-filled" size="15"  @click="showPassword2 = true"></uni-icons>
			</view>
		</view>
		
		<view class="bottom">
			<view class="button" @click="submit">提交</view>
			<view class="button" @click="back">返回</view>
		</view>
	</view>
</template>

<script>
	import apis from '@/api/index.js'
	import {
		requestApi,uphttp
	} from '@/utils/request.js'
	// 导入公共组件方法
	import common from '@/common/js/common.js';
	export default {
		data() {
			return {
				userInfo:{},
				showPassword:true,
				showPassword1:true,
				showPassword2:true,
			}
		},
		onLoad() {
			this.userInfo.userId = uni.getStorageSync("user").userId;
		},
		methods: {
			back(){
				uni.navigateBack({delta:1})
			},
			submit(){
				if(this.userInfo.newpassWord1!=this.userInfo.newpassWord){
					uni.showToast({
						icon:"error",
						title:"密码不一致"
					})
					this.userInfo.newpassWord1 = null;
					this.userInfo.newpassWord = null;
				}else if(this.userInfo.newpassWord.length<6){
					uni.showToast({
						icon:"error",
						title:"密码过短"
					})
					this.userInfo.newpassWord1 = null;
					this.userInfo.newpassWord = null;
				}else{
					requestApi(apis.user.changePwd,this.userInfo,'POST').then(res=>{
						if(res.code!=200){
							uni.showToast({
								icon:"error",
								title:"原密码错误"
							})
						}else if(res.code == 200){
							uni.showToast({
								icon:"success",
								title:"更新成功",
								duration:1500
							})
							setTimeout(()=>{
								uni.navigateTo({
									url:"/pages/login/login"
								})
							},2000)
						}
					})
				}
			}
		}
	}
</script>

<style>
.body {
		padding: 0 32rpx;
		min-height: 100vh;
		background-color: #fff;
	}
	.example-body {
		padding: 10px;
		padding-top: 0;
	}
	
	.img {
		width: 150rpx;
		height: 150rpx;
	}
	
	.item {
		display: flex;
		padding: 24rpx 0px;
		align-items: center;
		position: relative;
		/* justify-content: space-between; */
		border-bottom: 1px solid #fafafa;
	}
	
	.block {
		width: 100%;
		height: auto;
		border-bottom: 24rpx solid #F1F6FB;
		padding: 0 32rpx 32rpx;
		box-sizing: border-box;
		background-color: #FFFFFF;
	}
	
	.title {
		width: 160rpx;
		margin-right: 30rpx;
		font-family: 'PingFang SC';
		font-style: normal;
		font-weight: 400;
		font-size: 28rpx;
		line-height: 40rpx;
		color: rgba(51, 51, 51, 0.4);
		text-align: left;
	}
	
	.title1 {
		width: 160rpx;
		margin-right: 30rpx;
		font-family: 'PingFang SC';
		font-style: normal;
		font-weight: 400;
		font-size: 28rpx;
		line-height: 40rpx;
		color: rgba(51, 51, 51, 0.4);
		text-align: left;
		justify-content: space-between;
		position: absolute;
		top: -20rpx;
	}
	
	.in-ys {
		width: 80%;
		border-radius: 8rpx;
		background: #F6F6F6;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-right: 20rpx;
	}
	.button{
		
		width: 40%;
		
		color: #fff;
		background-color: #07b1ff;
		padding: 32rpx;
		border-radius: 64rpx;
		text-align: center;
	}
	.bottom{
		position: absolute;
		bottom: 40rpx;
		left: 50%;
		transform: translateX(-50%);
		width: 100%;
		display: flex;
		justify-content: space-between;
	}
</style>
